<template>
  <div class="timeline-container">
    <el-timeline>
      <el-timeline-item
        v-for="(event, index) in sortedEvents"
        :key="event.id"
        :timestamp="event.date"
        :color="colors[index % colors.length]"
        placement="top"
      >
        <div class="event-wrapper" @mouseenter="animateCard(index)">
          <el-card
            class="event-card"
            :class="{'active': activeIndex === index}"
            :style="{ '--hue': index * 60 }"
          >
            <div class="event-header">
              <h3 class="event-title">{{ event.title }}</h3>
              <span class="event-date">{{ event.date }}</span>
            </div>
            <p class="event-description">{{ event.description }}</p>
            <div class="event-icon">
              <i :class="event.icon"></i>
            </div>
          </el-card>
        </div>
      </el-timeline-item>
    </el-timeline>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeIndex: null,
      colors: ['#FF6B6B', '#4ECDC4', '#45B7D1', '#A37AFC', '#FFA36B'],
      events: [
        {
          id: 1,
          title: "项目启动",
          description: "正式启动新项目，组建核心团队，制定初步规划。",
          date: "2025-03-01",
          icon: "el-icon-check",
        },
        {
          id: 2,
          title: "需求分析",
          description: "完成用户需求调研和分析，确定产品功能范围。",
          date: "2025-02-15",
          icon: "el-icon-edit",
        },
        {
          id: 3,
          title: "原型设计",
          description: "完成产品原型设计并通过评审，进入开发阶段。",
          date: "2025-04-05",
          icon: "el-icon-opportunity",
        },
        {
          id: 4,
          title: "开发阶段",
          description: "核心功能开发完成，进入测试阶段。",
          date: "2025-05-20",
          icon: "el-icon-cpu",
        },
        {
          id: 5,
          title: "产品发布",
          description: "产品正式发布，获得市场良好反馈。",
          date: "2025-07-10",
          icon: "el-icon-success",
        },
      ],
    };
  },
  computed: {
    sortedEvents() {
      return [...this.events].sort((a, b) => new Date(a.date) - new Date(b.date));
    },
  },
  methods: {
    animateCard(index) {
      this.activeIndex = index;
    }
  }
};
</script>

<style scoped>
.timeline-container {
  max-width: 800px;
  margin: 40px auto;
  padding: 20px;
}

.event-wrapper {
  position: relative;
  padding: 10px 0;
}

.event-card {
  background: white;
  border: none;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: all 0.6s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.event-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 0;
  background: linear-gradient(to bottom, hsl(var(--hue), 100%, 70%), hsl(var(--hue), 100%, 50%));
  transition: height 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.event-card.active {
  transform: translateY(-5px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.event-card.active::before {
  height: 100%;
}

.event-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.event-title {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin: 0;
}

.event-date {
  font-size: 14px;
  color: #666;
}

.event-description {
  font-size: 14px;
  color: #555;
  line-height: 1.6;
  margin: 0;
}

.event-icon {
  position: absolute;
  right: 20px;
  top: 20px;
  font-size: 24px;
  opacity: 0.1;
  transition: all 0.6s ease;
}

.event-card.active .event-icon {
  opacity: 0.3;
  transform: scale(1.2);
}

/* Timeline dot animation */
.el-timeline-item__node {
  width: 16px;
  height: 16px;
  transition: all 0.6s ease;
}

.el-timeline-item__node:hover {
  transform: scale(1.2);
  box-shadow: 0 0 0 4px rgba(255, 107, 107, 0.3);
}

/* Timeline line animation */
.el-timeline-item__tail {
  transition: all 0.6s ease;
}

.event-wrapper:hover ~ .el-timeline-item__tail {
  background: linear-gradient(to bottom, #FF6B6B, #4ECDC4);
}
</style>
